//
//  CIViewController.m
//  CropImage
//
//  Created by liuzhen on 04/21/2016.
//  Copyright (c) 2016 liuzhen. All rights reserved.
//

#import "CIViewController.h"
#import "CropViewController.h"

@interface CIViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIImagePickerController *picker;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end

@implementation CIViewController

- (IBAction)pickPhoto:(id)sender {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.delegate = self;
    [self presentViewController:self.picker animated:YES completion:^{
        
    }];
}

- (IBAction)takePhoto:(id)sender {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.allowsEditing = NO;
    self.picker.delegate = self;
    [self presentViewController:self.picker animated:YES completion:^{
        
    }];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    CropViewController *crop = [[CropViewController alloc] init];
    crop.whRatio = 308.0f/114.0f;
    crop.cropImage = ^(UIImage *image) {
        NSLog(@"isStatusBarHidden %@, statusBarStyle %@", @([UIApplication sharedApplication].isStatusBarHidden), @([UIApplication sharedApplication].statusBarStyle));
        self.imageView.image = image;
        [self dismissViewControllerAnimated:YES completion:nil];
    };
    crop.editImage = info[UIImagePickerControllerOriginalImage];
    
    [self.picker pushViewController:crop animated:YES];
}

@end
